1 <?php
2 session_start();
// Use session variable on this page. This function must put on the top of page.
3 if
(!isset($_SESSION['username']) || $_SESSION['usertype'] !='admin'){ // if session variable "username" does not exist.
4 header(
"location:index.php?msg=Please%20login%20to%20access%20admin%20area%20!"); // Re-direct to index.php
5 }

6 else

7 {
8     include_once
"db.php";
9     error_reporting (E_ALL ^ E_NOTICE);
10
11     $tablename=$_POST[
'table'];
12     $
return=$_POST['return'];
13     $i=
0;
14     
foreach($_POST['checklist'] as $singleVar)
15                                     {
16             
17  $SQL =
"SELECT * FROM $tablename where id=$singleVar";
18 $result=mysql_query($SQL) or die(mysql_error());
19   $checkuser=mysql_num_rows($result);
20         
if($checkuser>0) {
21                                 
22                                                 
if($tablename=="stock_entries")
23                     {
24                     
25                                 $id=$singleVar;
26                                 $difference=$db->queryUniqueValue(
"SELECT quantity FROM stock_entries WHERE id=$id");
27                                 $name=$db->queryUniqueValue(
"SELECT stock_name FROM stock_entries WHERE id=$id");
28                                 $result=$db->query(
"SELECT * FROM stock_entries where id > $id");
29                                 
while ($line2 = $db->fetchNextObject($result)) {
30                                 $osd=$line2->opening_stock - $difference;
31                                 $csd=$line2->closing_stock - $difference;
32                                 $cid=$line2->id;
33                                 $db->execute(
"UPDATE stock_entries SET opening_stock=".$osd.",closing_stock=".$csd." WHERE id=$cid");
34                                     
35                                 }
36                                 $total = $db->queryUniqueValue(
"SELECT quantity FROM stock_avail WHERE name='$name'");
37                                 $total = $total - $difference;
38                                 $db->execute(
"UPDATE stock_avail SET quantity=$total WHERE name='$name'");
39                     }
40                     
if($tablename=="stock_sales")
41                 
42                     { $id=$singleVar;
43                                 $difference=$db->queryUniqueValue(
"SELECT quantity FROM stock_sales WHERE id=$id");
44                                 $sid=$db->queryUniqueValue(
"SELECT transactionid FROM stock_sales WHERE id=$id");
45                                 $id=$db->queryUniqueValue(
"SELECT id FROM stock_entries WHERE salesid='$sid'");
46                                 $name=$db->queryUniqueValue(
"SELECT stock_name FROM stock_entries WHERE id=$id");
47                                 $result=$db->query(
"SELECT * FROM stock_entries where id > $id");
48                                 
while ($line2 = $db->fetchNextObject($result)) {
49                                 $osd=$line2->opening_stock + $difference;
50                                 $csd=$line2->closing_stock + $difference;
51                                 $cid=$line2->id;
52                                 $db->execute(
"UPDATE stock_entries SET opening_stock=".$osd.",closing_stock=".$csd." WHERE id=$cid");
53                                     
54                                 }
55                                 echo
"sale $name";
56                                 $total = $db->queryUniqueValue(
"SELECT quantity FROM stock_avail WHERE name='$name'");
57                                 $total = $total + $difference;
58                                 $db->execute(
"UPDATE stock_avail SET quantity=$total WHERE name='$name'");
59                     }
60                                     
61                                     
62                                 mysql_query(
"DELETE FROM $tablename WHERE id=$singleVar") or die(mysql_error());
63                             
64                                 $i++;
65                     }
66                         
67                             }
68 header(
"location:$return?cmsg=$i Records Deleted Successfully!");
69                             
70     }
71     
72     
73                             
74                             ?>


Gõ tìm kiếm nhanh...